//生成时间:2023-03-30 17:22
var tuser={
    id:null,//编号
    Set_id:function(id){
        tuser.id=id.replace(/\'/g,"&apos;");
    },
    s_name:null,//姓名
    Set_s_name:function(s_name){
        if(s_name.length<1 || s_name.length>90){
            return '姓名的字数必须在1~90之间';
        }
        tuser.s_name=s_name.replace(/\'/g,"&apos;");
    },
    s_sex:null,//性别
    Set_s_sex:function(s_sex){
        if(s_sex.length<1 || s_sex.length>10){
            return '性别的字数必须在1~10之间';
        }
        var area=["男","女"];
        if(area.indexOf(s_sex)==-1){
            return '性别不在指定的范围内';
        }
        tuser.s_sex=s_sex.replace(/\'/g,"&apos;");
    },
    UseForm: function (elem) {
        for (var key in tuser) {
            if (typeof tuser[key] == "function") {
                continue;//过滤方法
            }
            if (elem.querySelector("#" + key) ==null) {
                continue;//过滤不存在表单组件
            }
            var val = "";
            if(['INPUT','SELECT','TEXTAREA'].indexOf(elem.querySelector("#"+key).nodeName)>-1){;
                val=elem.querySelector("#"+key).value;
            };
            if(['IMG'].indexOf(elem.querySelector("#"+key).nodeName)>-1){;
                val=elem.querySelector("#"+key).src;
            };
            var res = tuser["Set_" + key](val);
            if (res) {
                return res;
            }
        }
        return null;
    },
    CreateFormdata: function () {
        var postData = new FormData();
        for (var key in tuser) {
            if (typeof tuser[key] == "function") {
                continue;//过滤方法
            }
            if (tuser[key] == null) {
                  continue;
            }
            postData.append(key, tuser[key]);
        }
        return postData;
    },
    CreateJson: function () {
        var json = {};
        for (var key in tuser) {
            if (typeof tuser[key] == "function") {
                continue;//过滤方法
            }
            if (tuser[key] == null) {
                  continue;
            }
            json[key] = tuser[key];
        }
        return json;
    }
}
